package com.topscomm.meet.controller;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.topscomm.meet.pojo.MeetManageEntity;
import com.topscomm.meet.service.IMeetManageService;
import com.topscomm.pub.util.ConvertUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.meet.controller.auto.TaskManageControllerAuto;
import com.topscomm.pub.vo.Page;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: shenyouyi
 * @date: 2020-08-21
 * @description: 任务管理Controller
 * @modify:
 */
@RestController
@RequestMapping("meet/taskManage")
public class TaskManageController extends TaskManageControllerAuto implements IMeetTaskController {
	@Autowired
	private IMeetManageService meetManageService;

	/**
	 * @return
	 * @author: shenyouyi
	 * @date: 2020-08-21
	 * @param: paraMap
	 * @description: 重写查询列表接口
	 * @modify:
	 */
	@Override
	public ResponseResult<Object> list(@RequestParam(required = false) Map<String, Object> paraMap) {
		// edited by shenyouyi 2020-08-25 14:00:07
		// 不需要区分查询出当前登录人创建的任务了，都查询出来
		/*
		 * String sourceType = (String) paraMap.get("sourceType"); if
		 * (MeetSystemConst.MeetTaskSourceType.MeetCreate.equals(sourceType))
		 * {// 系统创建模块查询 String currentUserCode =
		 * this.getUserBean().getUser().getCode(); paraMap.put("initiatorcode",
		 * currentUserCode); }
		 */
		Page page = this.service.searchTaskFromOA(paraMap);
		return ResponseResult.ok(page);
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-25
	 * @return
	 * @description: 根据条件查询用户
	 * @modify:
	 */
	@GetMapping(value = "/queryUsersByCondition")
	public ResponseResult<Object> queryUsersByCondition(@RequestParam(required = false) Map<String, Object> paraMap) {
		List<Map<String, Object>> userList = this.service.searchUsersByCondition(paraMap);
		return ResponseResult.ok(userList);
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-22
	 * @param: paraMap
	 * @return
	 * @description: 创建
	 * @modify:
	 */
	@Override
	@PostMapping({ "/insert" })
	public ResponseResult<Object> insert(@RequestBody(required = false) Map<String, Object> paraMap) {
		// this.service.addTask(paraMap);
		this.service.addTaskBatch(paraMap);
		return ResponseResult.ok("保存成功，稍后同步到OA系统");
	}

	/**
	 * @author: shenyouyi
	 * @date: 2020-08-27
	 * @param: paraMap
	 * @return
	 * @description: 作废
	 * @modify:
	 */
	@PostMapping(value = "/drop")
	public ResponseResult<Object> drop(@RequestBody(required = false) Map<String, Object> paraMap) {
		this.service.dropTask(paraMap);
		return ResponseResult.ok("操作成功！");
	}

	/**
	* @Description:    任务督办模块查询列表页接口
	* @Author:         mengmeng
	* @Date:           2021/6/3 9:39
	* @Version:        1.0
	*/
	@GetMapping(value = "/taskSupervise")
	public ResponseResult<Object> taskSupervise(@RequestParam(required = false) Map<String, Object> paraMap) {
		String currentUserCode = getUserBean().getUser().getCode();
		paraMap.put("currentuser", currentUserCode);
		// 查询当前用户创建的会议和当前用户作为会议秘书的会议
		List<MeetManageEntity> meetManageEntities = meetManageService.queryByCondition(paraMap);
		String sourceIds = meetManageEntities.stream().map(MeetManageEntity::getMeetnum).collect(Collectors.joining(","));
		paraMap.put("sourceid", sourceIds);
		Page page = this.service.searchTaskFromOAByUser(paraMap);
		return ResponseResult.ok(page);
	}

}
